package 力扣.周赛.蔚来;

import org.junit.jupiter.api.Test;

public class 子字符串突变后可能得到的最大整数 {

    public String maximumNumber(String num, int[] change) {
        boolean flag = false;
        char[] chArr = num.toCharArray();
        for (int i = 0; i < chArr.length; i++) {
            int tmp = chArr[i] - '0';
            if (flag && tmp> change[tmp]) {
                break;
            }
            if (tmp < change[tmp]) {
                chArr[i] = (char) ('0' +change[tmp]);
                flag = true;
            }
        }
        return new String(chArr);
    }


    @Test
    void test(){
//        "132"
//[9,8,5,0,3,6,4,2,6,8]
        int[] change ={9,8,5,4,3,6,4,2,6,8};
        System.out.println(maximumNumber("132", change));
    }

}
